import requests
from concurrent.futures import ThreadPoolExecutor

# 接口 URL 模板
url_template = "http://106.55.8.90:7001/api/ccSmart/checkTopicByTrackSpanId/invoke?spanId={}"

# 不同的 spanId 列表
span_ids = [
"xeekq4ezpcvls",
"xe6xz0zwzc0e8",
"xej1amrw1yuio",
"xefibqx4a4oow",
"xekgqjbru7xmo",
"xeljzjt6a2z28",
"xelpmxsbfd3wg",
"xek9lmi8vr1mo",
"xehotrw9x9zb4",
"xein0t50dqm80",
"xekpydpfjuqdc",
"xeh6zhuspd4ao",
"xeg28yj652ww0",
"xeb8w5dsez4lc",
"xeguslsoqwikg",
"xejj4wt6togsg",
"xei8qzid666f4",
"xejtua189zbwg",
"xef64uuuzd728",

]

# 请求头
headers = {
    'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}

# 定义请求函数
def call_api(span_id):
    url = url_template.format(span_id)
    try:
        requests.get(url, headers=headers, timeout=1)  # 设置 timeout 避免阻塞
        print(f"Request sent with spanId={span_id}")
    except Exception as e:
        print(f"Error with spanId={span_id}: {e}")

# 使用线程池异步调用
with ThreadPoolExecutor(max_workers=10) as executor:  # 最多 10 个并发
    executor.map(call_api, span_ids)

print("All requests sent asynchronously!")